package com.pp.controller;


import com.pp.bean.GovGoodType;
import com.pp.commne.BaseController;
import com.pp.service.GovGoodTypeService;
import com.pp.util.Respons.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品类型表 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2019-04-02
 */
@Controller
@RequestMapping("/govGoodType")
@Api(value = "商品类型controller", tags = {"商品类型类"})
public class GovGoodTypeController {
    @Autowired
    GovGoodTypeService goodTypeService;

    /**
     * 查询所有商品类型
     *
     * @return
     */
    @ApiOperation(value = "查询所有商品类型")
    @RequestMapping(value = "/findGoodType", method = RequestMethod.POST)
    @ResponseBody
    public List<GovGoodType> findGoodType(@RequestBody GovGoodType goodType) {
        return goodTypeService.findType(goodType);
    }

    /**
     * 新增商品类型
     *
     * @return
     */
    @RequestMapping(value = "/saveGoodType", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "新增商品类型")
    public Map<String, Object> saveGoodType(@RequestBody GovGoodType govGoodType) {
        if (goodTypeService.save(govGoodType)) {
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }
    /**
     * 删除商品类型
     *
     * @return
     */
    @RequestMapping(value = "/deleteGoodType", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除商品类型")
    public Map<String, Object> findGoodType(@RequestParam("id")Long id) {
        if (goodTypeService.removeById(id)) {
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }
}
